import httpFetch from "share/httpFetch";
import { message } from "antd";
import config from "config";

const ReasonsServer = function (context) {
  context.setState({ loading: true });
  const realmId = config.realmIds[location.host] || config.realmId;
  return {
    // 获取机票理由
    async saveAirplaneReasons(params) {
      try {
        const res = await httpFetch.post("/open/user/api/config/saveOrderReason?realmId="+realmId, params, { source: "console" });
        return res;
      } catch (e) {
        dealWithErrorMes(e);
      } finally {
        context.setState({ loading: false });
      }
    },

    // 保存酒店理由
    async saveHotelReasons(params) {
      try {
        const response = await httpFetch.post("/open/user/api/config/saveHotelOrderReason?realmId="+realmId, params);
        return response;
      } catch (e) {
        dealWithErrorMes(e);
      } finally {
        context.setState({ loading: false });
      }
    },
  };
};

const dealWithErrorMes = (err) => {
  message.error(`${err.response.data.message}`);
};

export default ReasonsServer;
